<template>
  <div class="body">
    <!-- 搜索框 -->
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="用户昵称:" prop="userName" label-width="120px">
        <el-input v-model="queryParams.userName" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <!-- 表格 -->
    <el-table ref="multipleTable" :data="tableData" tooltip-effect="dark" style="width: 100%"
      @selection-change="handleSelectionChange" stripe>
      <el-table-column type="selection" width="55">
      </el-table-column>

      <el-table-column type="index" width="50" label="序号">
      </el-table-column>

      <el-table-column prop="loginName" label="登录名" width="120">
      </el-table-column>

      <el-table-column prop="userName" label="姓名" show-overflow-tooltip>
      </el-table-column>

      <el-table-column prop="deptName" label="部门" show-overflow-tooltip>
      </el-table-column>
      <el-table-column prop="scaleTitle" label="量表名称" show-overflow-tooltip>
      </el-table-column>
      <el-table-column fixed="right" label="操作" width="100">
        <template slot-scope="scope">
          <el-button @click="handleClick(scope.row)" type="text" size="small">查看</el-button>
          <el-button type="text" size="small">编辑</el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页 -->
    <div class="block">
      <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="currentPage"
        :page-sizes="[5, 10, 15, 20]" :page-size="queryParams.pageSize" layout="total, sizes, prev, pager, next, jumper"
        :total=total>
      </el-pagination>
    </div>
    <!-- 批量删除导出按钮 -->
    <div style="margin-top: 20px">
      <el-button @click="toggleSelection([tableData[1], tableData[2]])">批量删除</el-button>
      <el-button @click="toggleSelection()">批量导出</el-button>
    </div>

  </div>

</template>

<script>
import { listResult_personal, getResult_personal, delResult_personal, addResult_personal, updateResult_personal } from "@/api/mentalTest/personScore";
export default {
  data () {
    return {
      // 显示搜索条件
      showSearch: true,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        scaleId: null,
        scaleTitle: null,
        userId: null,
        loginName: null,
        userName: null,
        countScore: null,
        factorScore: null,
        resultContent: null,
        factorResult: null,
        userAnswer: null,
        classesName: null,
        deptName: null
      },
      tableData: [],
      multipleSelection: [],
      // 分页
      currentPage: 1,
      pageSize: 10,
      total: 0,
    }
  },
  created () {
    this.getList();
  },
  methods: {
    /** 搜索按钮操作 */
    handleQuery () {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery () {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 查看
    handleClick (row) {
      // console.log(row);
      this.$router.push({
        path: '/fileManagement/cepingchakan',
        query: {
          row: row
        }
      })
    },
    // 分页
    handleSizeChange (pageSize) {

      this.queryParams.pageSize = pageSize;
      this.getList();
    },
    handleCurrentChange (currentPage) {

      this.queryParams.pageNum = currentPage;
      this.getList();
    },
    /** 查询个人测评成绩报告列表 */
    getList () {
      this.loading = true;
      listResult_personal(this.queryParams).then(response => {
        this.result_personalList = response.rows;
        this.total = response.total;
        this.loading = false;
        this.tableData = response.rows
      });
    },
    toggleSelection (rows) {
      if (rows) {
        rows.forEach(row => {
          this.$refs.multipleTable.toggleRowSelection(row);
        });
      } else {
        this.$refs.multipleTable.clearSelection();
      }
    },
    handleSelectionChange (val) {
      this.multipleSelection = val;
    }
  }
}
</script>

<style scoped>
.body {

  margin-right: 40px;
  /* 右边距为20像素 */
  margin-left: 40px;
  /* 左边距为5像素 */
}
</style>